<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{margin: 0;padding:0;box-sizing: border-box}
        html, body{
            width: 100vw;
            height: 100vh;
            overflow: hidden;
        }
    </style>
</head>
<body>
    <canvas></canvas>

    <script>
        //获取 canvas 元素
        let canvas = document.querySelector('canvas');

        //设置宽度和高度
        canvas.width = document.documentElement.clientWidth;// 数字
        canvas.height = document.documentElement.clientHeight;

        //创建画笔对象
        let ctx = canvas.getContext('2d');
        ctx.strokeStyle = '#786';
        ctx.lineWidth = 10

        //绑定事件
        canvas.addEventListener('touchstart', function(e){
            ctx.beginPath();
            //移动画笔
            ctx.moveTo(e.changedTouches[0].clientX, e.changedTouches[0].clientY);
        })

        canvas.addEventListener('touchmove', function(e){
            //绘制
            ctx.lineTo(e.changedTouches[0].clientX, e.changedTouches[0].clientY);
            ctx.stroke();
        })

        canvas.addEventListener('touchend', function(){})

    </script>
</body>
</html>